var Fraction = {
    a : 0,
    b : 0,
    d : "",
    e : 0,
    fraction : function(num1, num2) {
        Fraction.a=num1;
        Fraction.b=num2;
        Fraction.appointment();
    },
    gcd : function(a, b) { //欧几里德算法
        return b==0? a: Fraction.gcd(b,a%b);
    },
    appointment : function() { // 约分操作
        if (Fraction.a == 0 || Fraction.b == 1) return; // 如果分子是0或分母是1就不用约分了
        Fraction.e = Fraction.gcd(Fraction.a,Fraction.b);
        Fraction.a /= Fraction.e;
        Fraction.b /= Fraction.e;
    },
    toFraction : function(){
        Fraction.d = Fraction.a+"/"+Fraction.b;
    },
    add: function (m, n) {
        m = m.toString();
        n = n.toString();
        // 分数加法，未校验数据格式正确性，请前置校验
        if (m == '0') return n;
        if (n == '0') return m;
        
        var m1 = 1, m2 = 1, n1 = 1, n2 = 1;
        if (m.length == 3) {
            m1 = m.split('/')[0];
            m2 = m.split('/')[1]
        }
        if (n.length == 3) {
            n1 = n.split('/')[0];
            n2 = n.split('/')[1];
        }

        Fraction.fraction(m1 * n2 + m2 * n1, m2 * n2);
        Fraction.toFraction();
        return Fraction.d;
    },
    sub: function (m, n) {
        m = m.toString();
        n = n.toString();
        // 分数减法，未校验数据格式正确性，请前置校验
        if (m == 0) return '-' + n;
        if (n == 0) return m;

        var m1 = 1, m2 = 1, n1 = 1, n2 = 1;
        if (m.length == 3) {
            m1 = m.split('/')[0];
            m2 = m.split('/')[1]
        }
        if (n.length == 3) {
            n1 = n.split('/')[0];
            n2 = n.split('/')[1];
        }

        Fraction.fraction(m1 * n2 - m2 * n1, m2 * n2);
        Fraction.toFraction();
        return Fraction.d;
    }

};